home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rjs.lha / RJS / String / paper / ruled.sty < prev    next >
Text File  |  1991-06-14  |  17KB  |  379 lines

  1. % file: ruled.tex            TeXsis                  version 2.14
  2. % :: $Header: /usr2/myers/texsis/RCS/ruled.tex,v 1.5 90/06/21 13:47:44 myers Stab $
  3. %======================================================================*
  4. %  RULED TABLES.                                E. Myers and F.E. Paige
  5. %
  6. %       The following macros will typeset tables with vertical and
  7. % horizontal rules. The syntax is similar to Ray Cowan's TABLES.TEX,
  8. % but the macros have been completely rewritten. Vertical and horizontal 
  9. % rules are drawn by macros using vertical spacing controlled by struts.
  10. % Usage:
  11. %       \ruledtable
  12. %       <item> <tab> ... <item> <cr>
  13. %       ...
  14. %       <item> <tab> ... <item> \endruledtable
  15. % where <item> is an element of the table (every row must have exactly 
  16. % the same number of items, although some may be blank), <tab> is any
  17. % one of
  18. %     &                 for no vertical rule
  19. %     |  [or \vb]       for vertical rule
  20. %     \| [or \Vb]       for thick vertical rule
  21. %     \dbl              for double vertical rule
  22. % and <cr> is any one of
  23. %     \nr               for no horizontal rule
  24. %     \cr               for horizontal rule
  25. %     \CR [or \crthick] for thick horizontal rule
  26. % The last <cr> must be omitted in favour of the \endruledtable
  27. %
  28. %  For horizontal rules across only some columns use
  29. %       ... \nr
  30. %       \crule | \cskip & \Crule ... \crpart
  31. % where \crpart is a special \cr for the partial rule line and
  32. %       \cskip          no rule for column
  33. %       \crule          horizontal rule for column
  34. %       \Crule          thick horizontal rule for column
  35. % The number of columns must be identical to the other rows.
  36. %
  37. % To change the appearance of the table, modify \TableItem.
  38. %  Several modifications are built in:
  39. %       \LeftJustifyTables      left justify each column
  40. %       \RightJustifyTables     right justify each item
  41. %       \NoJustifyTables        center each item (default)
  42. %       \TightTables            use \ horizontal spacing
  43. %       \LooseTables            use \quad horizontal spacing (default)
  44. %
  45. % Use \bigitem to expand the vertical strut for high or deep items. 
  46. %
  47. %       These macros have been reorganized and substantially revised from
  48. % version 2.13. The following functional changes have been made:
  49. %       (1) The @ signs have been removed from the names of the macros
  50. % used to save the Plain \cr, \span, and & so that they can be used to
  51. % modify the preamble. See above.
  52. %       (2) Macros for partial horizontal rules have been added.
  53. %======================================================================*
  54. % Counters and such:     
  55. \catcode`@=11                                   % @ is a letter here
  56. \catcode`\|=12                                  % make sure | is not active
  57. \catcode`\&=4                                   % and that & is alignment tab
  58.  
  59. \newcount\ncols         \ncols=\z@              % number of columns in table
  60. \newcount\nrows         \nrows=\z@              % number of rows in table
  61. \newcount\curcol        \curcol=\z@             % current column counter
  62. \let\currow=\nrows                              % current row counter
  63.      
  64. \newdimen\thinsize      \thinsize=0.6pt         % thin rule width
  65. \newdimen\thicksize     \thicksize=1.5pt        % thick rule width
  66.  
  67. \newif\iftableinfo      \tableinfotrue          % report rows and columns? Yes
  68. \newif\ifcentertables   \centertablestrue       % center tables? Yes
  69. \def\centeredtables{\centertablestrue}%
  70. \def\noncenteredtables{\centertablesfalse}%
  71. \def\nocenteredtables{\centertablesfalse}%      % synonym !
  72.      
  73. \let\plaincr=\cr                        % save real \cr
  74. \let\plainspan=\span                    % save real \span
  75. \let\plaintab=&                         % save real alignment tab &
  76. \def\ampersand{\char`\&}%               % to print `&' in text
  77. \let\lparen=(                           % save left paren     
  78. \let\NX=\noexpand                       % shorthand for \noexpand is \NX
  79.  
  80. % geek hack
  81.  
  82. \def\line2{\hbox to\hsize}
  83.  
  84. %---------------------------------------*
  85. % Main macros:
  86. %       \ruledtable <table stuff> \endruledtable turns on the ruled
  87. % table definitions and makes the table with \halign. It handles all
  88. % the control stuff; the real work is done by \@RuledTable.
  89.      
  90. \def\ruledtable{\relax                          % make ruled table
  91.     \@BeginRuledTable                           % initialize table
  92.     \@RuledTable}%                              % now process table body
  93.  
  94. %  \@BeginRuledTable does all the work of setting things up before
  95. % we read in the body of the table
  96.  
  97. \def\@BeginRuledTable{%                         % initialize table
  98.    \ncols=0\nrows=0                             % reset row and column count
  99.    \begingroup                                  % keep the following local
  100.     \offinterlineskip                           % so vrules touch
  101.     \def~{\phantom{0}}%                         % ~ is phantom digit
  102.     \def\span{\plainspan\omit\relax\colcount\plainspan}%  \span USER columns
  103.     \let\cr=\crrule                             % \cr gives a \tablerule
  104.     \let\CR=\crthick                            % \CR gives a \thickrule
  105.     \let\nr=\crnorule                           % \nr give no rule
  106.     \let\|=\Vb                                  % thick vrule between columns
  107. % support old \tablestrut in place of \tstrut if it exists
  108. %
  109.     \ifx\tablestrut\undefined\relax             % if not defined, no problem
  110.     \else\let\tstrut=\tablestrut\fi             % use \tablestrut
  111. %
  112.     \catcode`\|=13 \catcode`\&=13\relax         % make | and & active
  113.     \TableActive                                % | and & get active \def`s
  114.     \curcol=1                                   % reset column count
  115. %
  116. % define \Halign to do an \halign with or without a width
  117. %
  118.     \ifdim\tablewidth>-\maxdimen\relax          %
  119.       \edef\@Halign{\NX\halign to \NX\tablewidth\NX\bgroup\TablePreamble}% 
  120.       \tabskip=0pt plus 1fil                    % let things stretch
  121.     \else                                       %
  122.       \edef\@Halign{\NX\halign\NX\bgroup\TablePreamble}% 
  123.       \tabskip=0pt                              % no stretch between columns
  124.     \fi                                         %
  125. %
  126. % center text if needed
  127. %
  128.     \ifcentertables                             % should table be centered?
  129.        \ifhmode\vskip 0pt\fi                    % yes: force vertical mode
  130.        \line2\bgroup\hss                         % center across page
  131.     \else\hbox\bgroup                           % else: just put in \hbox
  132.     \fi}%                                       % end of \@BeginRuledTable
  133.  
  134.  
  135. %       \@RuledTable builds the table with \@Halign and getting the
  136. % table body text as its argument.
  137.  
  138. \long\def\@RuledTable#1\endruledtable{%         % ruled table alignment
  139.    \vrule width\thicksize                       % thick rule on side
  140.      \vbox{\@Halign                             % then do \halign
  141.        \thickrule                               % thick rule on top
  142.        #1\relax                                 % body of table
  143.        \tstrut                                  % vertical strut for last line
  144.        \plaincr\thickrule                       % \cr, thick rule on bottom
  145.      \egroup}%                                  % end of \halign and \vbox
  146.    \vrule width\thicksize                       % thick rule on side, end \hbox
  147.    \ifcentertables\hss\fi\egroup                % finish table centering
  148.   \endgroup                                     % end group from \ruledtable
  149.   \global\tablewidth=-\maxdimen                 %   and reset width
  150.   \iftableinfo                                  % report rows and columns
  151.       \immediate\write16{[Nrows=\the\nrows, Ncols=\the\ncols]}%
  152.    \fi}%                                        % end of \@RuledTable
  153.      
  154. %---------------------------------------*
  155. % Preamble and item macros:
  156. %       This is the preamble for the \halign in \ruledtable. 
  157. % To change how each item is processed change \TableItem.
  158. % To make a more complicated table you can change the \TablePreamble,
  159. % but if yo do so use the following substitutions in a standard \halign 
  160. % preamble:
  161. %    for  &     use     \plaintab
  162. %    for  \cr   use     \plaincr
  163. %    for  #     use     ##
  164. %    for  ##    use     ####
  165. % and put \linecount in the first column so that line counting
  166. % works properly.
  167.  
  168. \def\TablePreamble{%                    % \ruledtable preamble
  169.    \linecount                           % count this line
  170.    \TableItem{####}%                    % the first item
  171.    \plaintab\plaintab                   % && means repeat this
  172.    \TableItem{####}%                    % the subsequent items
  173.    \plaincr}%                           % end of preamble
  174.  
  175. %       \TableItem contains glue or spacing around the item
  176.  
  177. \def\@TableItem#1{%                             % centers item in ruled table
  178.    \hfil\tablespace                             % left glue
  179.    #1\relax                                     % item
  180.    \tablespace\hfil                             % right glue
  181.     }%
  182.  
  183. \def\@tableright#1{%                    % right justifies item in ruled table
  184.    \hfil\tablespace\relax               % left glue
  185.    #1\relax                             % item
  186.    \tablespace\relax}%                  % right glue
  187.  
  188. \def\@tableleft#1{%                     % left justifies item in ruled table
  189.    \tablespace\relax                    % left glue
  190.    #1\relax                             % item
  191.    \tablespace\hfil}%                   % right glue
  192.  
  193. \let\TableItem=\@TableItem              % default is centered
  194.      
  195. \def\RightJustifyTables{\let\TableItem=\@tableright}%   % to right justify
  196. \def\LeftJustifyTables{\let\TableItem=\@tableleft}%     % to left justify
  197. \def\NoJustifyTables{\let\TableItem=\@TableItem}%       % to center
  198.  
  199. \def\LooseTables{\let\tablespace=\quad}%        % table spacing is \quad
  200. \def\TightTables{\let\tablespace=\space}%       % table spacing is space
  201. \LooseTables                                    % default is \quad
  202.  
  203. %---------------------------------------*
  204. % Table Height and Width:
  205. %
  206. %  Normally tables are set to their natural width.  If \tablewidth
  207. %  has been set then we set the table to that width instead,
  208. %  but only for the next table.  Then \tablewidth is turned off
  209.  
  210.  
  211. \newdimen\tablewidth    \tablewidth=-\maxdimen  % start ``turned off''
  212.  
  213. %      \setRuledStrut sets up the vertical strut \tstrut with
  214. % the appropriate dimensions to hold up one line of a ruled table. 
  215.  
  216.  
  217. \def\setRuledStrut{% sets interlines spacing for ruled tables
  218.    \dimen@=\baselineskip                        % \dimen@ = extra space
  219.    \advance\dimen@ by-\normalbaselineskip       % between lines
  220.    \ifdim\dimen@<.5ex \dimen@=.5ex\fi           % minimum space
  221.    \setbox0=\hbox{\lparen}%                     % get character size
  222.    \dimen1=\dimen@ \advance\dimen1 by \ht0      % space above line
  223.    \dimen2=\dimen@ \advance\dimen2 by \dp0      % space below line
  224.    \def\tstrut{\vrule height\dimen1 depth\dimen2 width\z@}%
  225.    }%
  226.  
  227. \def\tstrut{\vrule height 3.1ex depth 1.2ex width 0pt}%  default
  228.  
  229.  
  230. %      \tstrut does not produce the correct spacing if the entry in
  231. % the table is too high. The following constructs a strut higher than its
  232. % argument and then prints the argument. The minimum space value should
  233. % be the same as in \setRuledStrut. 
  234.  
  235.  
  236. \def\bigitem#1{%                                % larger table entry
  237.    \setbox0=\hbox{#1}%                          % put arg. in box and
  238.    \dimen1 =\ht0 \dimen2 =\dp0                  % get its size
  239.    \dimen@ =\baselines@ve                       % \dimen@ = extra space
  240.    \advance\dimen@ by-\normalbaselineskip       %   between lines
  241.    \ifdim\dimen@<.25ex \dimen@=.25ex\fi         % minimum space
  242.    \advance\dimen1 by \dimen@                   % space above line
  243.    \advance\dimen2 by \dimen@                   % space below line
  244.    \vrule height\dimen1 depth\dimen2 width\z@   % make strut to size
  245.    \copy0}%                                     % print argument
  246.  
  247.  
  248. %       \vctr{stuff} centers the stuff vertically, so that it can
  249. % appear between two ROWS.
  250.      
  251. \def\vctr#1{\hfil\vbox to 0pt{\vss\hbox{#1}\vss}\hfil}%
  252.  
  253. %---------------------------------------*
  254. % Vertical rules:
  255. %       \tab, \vb and \Vb are used in a table to separate columns with no
  256. % rule, a thin rule, or a thick rule, respectively.  \nextcolumn{<rule>} skips
  257. % to  the next column and puts the <rule> between columns.  Use this to build
  258. % your own separators.
  259.      
  260. \def\nextcolumn#1{%                             % move to next col.
  261.    \plaintab\omit#1\relax\colcount              % tab, insert #1, count
  262.    \plaintab}%                                  % tab to next user col.
  263.      
  264. \def\tab{%                                      % no rule between columns
  265.    \nextcolumn{\relax}}%                        % count column
  266.  
  267. \let\novb=\tab                                  % synonym for \tab
  268.  
  269. \def\vb{%                                       % thin rule between columns
  270.    \nextcolumn{\vrule width\thinsize}}%         % count and rule
  271.  
  272. \def\Vb{%                                       % THICK rule between columns
  273.    \nextcolumn{\vrule width\thicksize}}%        % count and thick rule
  274.  
  275. \def\dbl{%                                      % double rule between columns
  276.    \nextcolumn{\vrule width\thinsize            % count and rule
  277.    \hskip\thinsize\vrule width\thinsize}}%      % and skip and rule
  278.  
  279. %       \TableActive makes | the same as \vb and & the same as \tab so
  280. % these single characters can be used between columns. Here we have to
  281. % make & and | active so we get the active version of the characters,
  282. % hence the temporary change of \catcode.
  283.      
  284. {\catcode`\|=13 \let|0
  285.  \catcode`\&=13 \let&0
  286.  \gdef\TableActive{\let|=\vb \let&=\tab}%
  287. }% end \catcode`s
  288.  
  289. %---------------------------------------*
  290. % Horizontal rules:
  291. %       These replacements for \cr put a wide \vrule at the end of the
  292. % line and maybe put a rule under the line, then begin the next line
  293. % with the wide \vrule from the preamble.
  294.      
  295.  
  296. \def\crrule{\relax                      % \cr plus rule
  297.    \tstrut                              % strut for spacing
  298.    \plaincr\tablerule                   % \cr, regular rule below line
  299.   }%
  300.  
  301. \def\crthick{\relax                     % \cr plus thick rule
  302.    \tstrut                              % strut for vertical spacing
  303.    \plaincr\thickrule                   % \cr, rule, begin next line
  304.   }%                
  305.      
  306. \def\crnorule{\relax                    % \cr plus no rule
  307.    \tstrut                              % strut for spacing
  308.    \plaincr                             % \cr, norule, begin next line
  309.    }%
  310.    
  311. \def\crpart{\plaincr}%                  % for partial rules, no strut
  312.  
  313.  
  314. %       These rules go across the table.
  315.      
  316. \def\tablerule{\noalign{\hrule height\thinsize depth 0pt}}%
  317. \def\thickrule{\noalign{\hrule height\thicksize depth 0pt}}%
  318.  
  319.  
  320. %       Rules for individual columns. You must use \cskip in columns
  321. % with no rules to \omit the \TablePreamble.
  322.  
  323. \def\cskip{\omit\relax}%
  324. \def\crule{\omit\leaders\hrule height\thinsize depth0pt\hfill}%
  325. \def\Crule{\omit\leaders\hrule height\thicksize depth0pt\hfill}%
  326.      
  327. %---------------------------------------*
  328. % Counting macros:     
  329. %       These macros count rows and columns of the table. After the
  330. % first line has been processed \the\ncols is the total number of
  331. % columns in the table, which may be useful. During processing,
  332. % \the\curcol is the number of the current column, while \the\currow is
  333. % the number of the current row.
  334.      
  335.  
  336. \def\linecount{\relax\global\ncols=\curcol      % save column count in \ncols
  337.    \global\curcol=1                             % and reset counter
  338.    \global\advance\nrows by 1\relax}%           % and advance row counter
  339.      
  340. \def\colcount{\relax                            %
  341.    \global\advance\curcol by 1\relax}%          % advance column counter
  342.  
  343. %---------------------------------------*
  344. % TEXT TABLES.
  345. %  To put text in a table use \para{<text>}, with \parasize set
  346. %  to the desired width of the text.
  347.  
  348.  
  349. \newdimen\parasize      \parasize=4in           % paragraph size in tables
  350.  
  351. \long\def\para#1{%
  352.   \vtop{\hsize=\parasize                %       
  353.    \baselineskip=14pt \lineskip=1pt     %
  354.    \lineskiplimit=1pt                   %
  355.    \noindent #1\relax                   %
  356.    \vrule width 0pt depth 6pt}%         % hold depth of box
  357. }%
  358.  
  359. %---------------------------------------*
  360. % TABLES.TEX
  361. %   For compatability with Cowan's TABLES.TEX we also allow the
  362. % syntax \begintable ... \endtable, which do the same thing.
  363. %
  364.  
  365. \def\begintable{\relax                          % make ruled table
  366.     \@BeginRuledTable                           % initialize table
  367.     \@begintable}%                              % now process table body
  368.  
  369. \long\def\@begintable#1\endtable{%              % ruled table alignment
  370.    \@RuledTable#1\endruledtable}%               % same as \ruledtable
  371.  
  372. %---------------------------------------*
  373. % Turn off @ as letter before we exit
  374.  
  375. \catcode`@=12                                   % @ is not a letter
  376.  
  377. %>>> EOF TXSruled.tex <<<
  378.